﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using Ionic.Zip;
using System.ComponentModel;

namespace Hal.Zip.WPF.GUI
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow
	{
		public MainWindow()
		{
			InitializeComponent();
		}

		

		private void btnZipIt_Click(object sender, RoutedEventArgs e)
		{
			DoStuff();
		}

		private void DoStuff()
		{
			if ((pickFolder.Text + "" == "") || (pickSaveFile.Text + "" == ""))
			{
				MessageBox.Show("Please select a directory and name the zip file before you continue.");
				return;
			}
			
			string sNameIn = pickFolder.Text.Trim();
			string sNameOut = pickSaveFile.Text.Trim();

			string sPassword = "";
			bool bEncryt = (bool)chkEncrypt.IsChecked;

			if(bEncryt)
			{
				var frmPwd = new frmPassword();
				
				frmPwd.ShowDialog();
				if(frmPwd.DidCancel)
				{
					this.Show();
					return;
				}
				sPassword = frmPwd.Password;
				frmPwd.Password = "";
				frmPwd.Close();
				frmPwd = null;
			}
			
			var frmStat = new frmStatus();
			
			frmStat.DirectoryToZip = sNameIn;
			frmStat.ArchiveName = sNameOut;
			frmStat.Password = sPassword;

			frmStat.ZipDirectory();
			frmStat.ShowDialog();

			frmStat.DirectoryToZip = "";
			frmStat.ArchiveName = "";
			frmStat.Password = "";

			frmStat.Close();
			frmStat = null;
		}
	}
}